""" AdminRole Model """

from masoniteorm.models import Model
import datetime


class AdminRole(Model):
    """AdminRole Model"""

    @classmethod
    def generate_log(cls, title):
        """
        生成日志
        @param string title: 标题
        @return: None
        """
        created_at = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        cls.create({
            'title': title,
            'created_at': created_at,
            'updated_at': created_at
        })

    @classmethod
    def get_title(cls):
        """
        获取角色
        @return: [{'id': 1, 'title': '管理员'}, {'id': 2, 'title': '测试人员'}]
        """
        roles = cls.get()
        data = []
        if roles is not None:
            for role in roles:
                data.append({'id': role.id, 'title': role.title})
        return data
